/**
 * 反馈
 */
var localStorageManagers = require('script/localStorageManagers.js');
mui.init({
	swipeBack: true
});
FastClick.attach(document.body);
//加载plusReady
mui.plusReady(function() {
	plusReady();
});
//plusReady
function plusReady() {
	//保存
	mui('header').on('tap', '#savequesbtn', saveQuestion);
	//@提醒
	mui('.mui-content').on('tap', '.tixingdiv', openTixing);
}
//保存问题
function saveQuestion() {
	var quesContent = document.getElementById('quescontent').value;
	if (quesContent.length == 0) {
		mui.toast("请填写问题内容");
		return;
	}
	if (quesContent.length > 200) {
		mui.toast("最多不超过100字！");
		return;
	}
	var atusers = document.getElementById('atusers').value;
	//if (atusers.length == 0) {
	//	mui.toast("请选择需要@的人");
	//	return;
	//}
	var userid = localStorageManagers.getUseridSession();
	var data = {
		userId: userid,
		questionContent: quesContent,
		atusers: atusers
	};
	var url = serverAjax + "mobile/studycenter/SaveQuestion.do";
	mui.ajax(url, {
		data: data,
		type: 'post',
		dataType: 'json',
		timeout: 10000,
		success: function(data) {
			if (data != 0) {
				mui.toast("提交问题成功");
				var parentWebView = plus.webview.getWebviewById("selfcenter/question/questionindex");
	            parentWebView.evalJS("ajaxLoad()");
				mui.back();
			}
		},
		error: function(e1, e2, e3) {
			ajaxErrorTip();
			console.log(e1);
		}
	});
}
//打开At选择框
function openTixing() {
	var userids = document.getElementById('atusers').value;
	mui.openWindow({
		url: 'attoteacher.html',
		id: 'selfcenter/question/attoteacher',
		extras: {
			userids: userids
		}
	});
}
//设置@对象
function setAtDiv(userids, usernames) {
	document.getElementById('tixingtitle').innerHTML = '<span style="color:#6990ff;">@' + usernames + '</span>';
	document.getElementById('atusers').value = userids;
}